        /**
         * 先录入学校，派人去沟通，沟通记录，如果同意，然后回来申请立项，待审核
        */
        //学校数据
        var totalPages;//总页数
        var currentPage = 1;//当前页码
        var page = 5;//每页显示条数
        //调用
        //存数据
        var schoolData=JSON.stringify(shoolData);
        localStorage.setItem("schoolData",schoolData);
        //取数据
        var shoolData=JSON.parse(localStorage.getItem("schoolData"));
        // var staffDate=JSON.parse(localStorage.getItem("staffDate"));
        // var departmentDate=JSON.parse(localStorage.getItem("departmentDate"));
        getPages();
        addpages();
        showData();
        getDeptList();
        $("#tbList input").click(check);
        $("#addNewSchool #addSchoolBtn").click(addNewSchools);
        
        //查看学校的所有信息
        $("#tbList").on("click", ".displayData", function () {
            $("#showSchool").modal('show');
            //当前等点击的学校id
            var id = $(this).parent().parent().find(".id").text();
            //遍历所有数据
            for (var j = 0; j < shoolData.length; j++) {
                if (id == shoolData[j].shoolId) {
                    $("#showDataList #shname").html(shoolData[j].shoolNam);
                    $("#showDataList #shCity").html(shoolData[j].shoolArea);
                    $("#showDataList #shAddress").html(shoolData[j].shoolAddress);
                    $("#showDataList #shTel").html(shoolData[j].shoolTel);
                    $("#showDataList #shMaster").html(shoolData[j].headmaster);
                    $("#showDataList #sNum").html(shoolData[j].studentNub);
                    $("#showDataList #TNum").html(shoolData[j].teacherNub);
                    $("#showDataList #shIP").html(shoolData[j].IP);
                    $("#showDataList #sShuoming").html(shoolData[j].iiustrate);
                    $("#showDataList #fuzeDept").html(getDepname(shoolData[j].staId));//通过员工id找部门
                    $("#showDataList #fuzePople").html(getPeople(shoolData[j].staId));
                    $("#showDataList #currentStatu").html(statusPuanduan(id));
                    $("#showDataList #luruTime").html(shoolData[j].addTime);
                    $("#showDataList #shenqingTime").html(shoolData[j].applyTime);
                    $("#showDataList #pizhunTime").html(shoolData[j].allowedTime);
                    $("#showDataList #yijian").html(shoolData[j].opinion);
                    //沟通记录
                    //获取沟通记录
                    $(" #recodeTb").html("");
                    var jilu = shoolData[j].recordInfo;
                    // console.log(jilu)
                    for (var i = 0; i < jilu.length; i++) {
                        $("#showDataList #recodeTb").append(`<tr>
                                        <td>${jilu[i].contactTime}</td>
                                        <td>${jilu[i].schoolPeople}</td>
                                        <td>${jilu[i].schoolJob}</td>
                                        <td>${getPeople(jilu[i].staId)}</td>
                                        <td>${jilu[i].content}</td>
                                    </tr>`);
                    }
                }
            }

        });
        
        //录入学校  
        function addNewSchools() {
            //获取输入的值
            var sid = $("#addNewSchool #sId").val();
            var sname = $("#addNewSchool #sName").val();
            var scity = $("#addNewSchool #sCity").find("option:selected").val();
            var saddress = $("#addNewSchool #sAddress").val();
            var sheadmaster = $("#addNewSchool #sheadmaster").val();
            var stel = $("#addNewSchool #sTelNum").val();
            var stuNum = $("#addNewSchool #stuNum").val();
            var teacherNum = $("#addNewSchool #teacherNum").val();
            var sIP = $("#addNewSchool #sIP").val();
            var dept = $("#addNewSchool #dept").find("option:selected").val();
            var shuoming = $("#addNewSchool #shuoming").val();
            var fuzePople = $("#addNewSchool #fuzePople").val();
            if(sid && sname && scity && saddress && stel){
                     //加入数组，并且生成录入时间
                    var adddate = new Date().toLocaleDateString();
                    var obj = {
                        "shoolId": sid, "shoolNam": sname, "shoolArea": scity, "shoolAddress": saddress,
                        "headmaster": sheadmaster, "shoolTel": stel, "teacherNub": teacherNum, "studentNub": stuNum,
                        "IP": sIP, "iiustrate": shuoming, "manager": fuzePople, "staId": getEmpoId(fuzePople), "addTime": adddate, "status": "A",
                        applyTime: "", allowedTime: "", opinion: "", recordInfo: [], ActivityContent: []
                    };
                    // console.log(obj);
                    shoolData.push(obj);
                    schoolData=JSON.stringify(shoolData);
                    localStorage.setItem("schoolData",schoolData);
                    //重新生成页码
                    getPages();
                    showData();
                    $("#addNewSchool #sId").val("");
                    $("#addNewSchool #sName").val("");
                    $("#addNewSchool #sCity").find("option:selected").val("");
                    $("#addNewSchool #sAddress").val("");
                    $("#addNewSchool #sheadmaster").val("");
                    $("#addNewSchool #sTelNum").val("");
                    $("#addNewSchool #stuNum").val("");
                    $("#addNewSchool #teacherNum").val("");
                    $("#addNewSchool #sIP").val("");
                    $("#addNewSchool #dept").find("option:selected").val("");
                    $("#addNewSchool #shuoming").val("");
                    $("#addNewSchool #fuzePople").val("");
                    $("#addNewSchool").find("span").remove();
            } else{
                    alert("请输入后再提交");
                    $("#addNewSchool #sId").val("");
                    $("#addNewSchool #sName").val("");
                    $("#addNewSchool #sCity").find("option:selected").val("");
                    $("#addNewSchool #sAddress").val("");
                    $("#addNewSchool #sheadmaster").val("");
                    $("#addNewSchool #sTelNum").val("");
                    $("#addNewSchool #stuNum").val("");
                    $("#addNewSchool #teacherNum").val("");
                    $("#addNewSchool #sIP").val("");
                    $("#addNewSchool #dept").find("option:selected").val("");
                    $("#addNewSchool #shuoming").val("");
                    $("#addNewSchool #fuzePople").val("");
                    $("#addNewSchool").find("span").remove();
                }
        };
        //修改学校信息
        $("#tbList").on("click", ".updateData", function () {
            $("#updateSchool").modal('show');
            //当前等点击的学校id
            var id = $(this).parent().parent().find(".id").text();
            for (var j = 0; j < shoolData.length; j++) {
                if (id == shoolData[j].shoolId) {
                    $("#updateSchool #UPshname").val(shoolData[j].shoolNam);
                    $("#updateSchool #UPshCity").val(shoolData[j].shoolArea);
                    $("#updateSchool #UPshAddress").val(shoolData[j].shoolAddress);
                    $("#updateSchool #UPshTel").val(shoolData[j].shoolTel);
                    $("#updateSchool #UPshMaster").val(shoolData[j].headmaster);
                    $("#updateSchool #UPsNum").val(shoolData[j].studentNub);
                    $("#updateSchool #UPTNum").val(shoolData[j].teacherNub);
                    $("#updateSchool #UPshIP").val(shoolData[j].IP);
                    $("#updateSchool #UPsShuoming").val(shoolData[j].iiustrate);
                    $("#updateSchool #UPfuzeDept").val(getDepname(shoolData[j].staId));//通过员工id找部门
                    $("#updateSchool #UPfuzePople").val(getPeople(shoolData[j].staId));
                    $("#updateSchool #UPcurrentStatu").val(statusPuanduan(id));
                    $("#updateSchool #UPluruTime").val(shoolData[j].addTime);
                    $("#updateSchool #UPshenqingTime").val(shoolData[j].applyTime);
                    $("#updateSchool #UPpizhunTime").val(shoolData[j].allowedTime);
                    $("#updateSchool #UPyijian").val(shoolData[j].opinion);
                    
                }
            }   
            //修改
            $("#updateSchoolBtn").click(function(){
                var names = $("#updateSchool #UPshname").val();
                var tel = $("#updateSchool #UPshTel").val();
                var master = $("#updateSchool #UPshMaster").val();
                var stu = $("#updateSchool #UPsNum").val();
                var teach = $("#updateSchool #UPTNum").val();
                var ip = $("#updateSchool #UPshIP").val();
                var sm = $("#updateSchool #UPsShuoming").val();
                for (var l = 0; l < shoolData.length; l++) {
                    if (id == shoolData[l].shoolId) {
                        //修改
                        shoolData[l].shoolNam = names;
                        shoolData[l].shoolTel = tel;
                        shoolData[l].headmaster = master;
                        shoolData[l].studentNub = stu;
                        shoolData[l].teacherNub = teach;
                        shoolData[l].IP = ip;
                        shoolData[l].iiustrate = sm;
                    }
                }
                schoolData=JSON.stringify(shoolData);
                localStorage.setItem("schoolData",schoolData);
                showData();
            })
        });
        //删除学校
        $("#delSchool").click(function () {
            //判断是否选中
            var arrInput = $(".table_content input");
            var hasCheck = false;
            for (var i = 0; i < arrInput.length; i++) {
                if (arrInput[i].checked) {
                    hasCheck = true;
                    break;
                }
            }
            if (hasCheck == false) {
                $("#placeholder").modal("show");
            } else {
                $("#delholder").modal("show");
                $("#confirm").click(function () {
                    $("#tbList input").each(function (index, item) {
                        if (item.checked == true) {
                            $(item).parent().parent().remove();
                            var delId = $(item).parent().parent().find(".id").text();
                            delData(delId);
                            schoolData=JSON.stringify(shoolData);
                            localStorage.setItem("schoolData",schoolData);
                            //重新生成页码
                            getPages();
                            showData();
                        }
                        item.checked = false;
                    });
                });
                $("#cancel").click(function () {
                    $("#tbList input").each(function (index, item) {
                        if (item.checked == true) {
                            item.checked = false;
                        }

                    });
                });
            }
           
        });

        //申请立项，生成时间
        $("#apply").click(function () {
            $("#applylist").html("");
            //选择学校,并且当前学校是接洽中
            for (var i = 0; i < shoolData.length; i++) {
                if (shoolData[i].status == "A") {
                    console.log(shoolData[i])
                    //显示学校
                    $("#applylist").append(`<option>${shoolData[i].shoolNam}</option>`);
                }
            }
        });
        $("#applySchool .btn").click(function () {
            //选中的值，根据学校名，添加录入时间
            var name = $("#applylist").find("option:selected").text();
            var time = new Date().toLocaleDateString();
            //添加时间,改变状态
            for (var i = 0; i < shoolData.length; i++) {
                if (shoolData[i].shoolNam == name) {
                    shoolData[i].applyTime = time;
                    shoolData[i].status = "B";
                    showData();
                    //placeholder
                    $("#placeholder .dongtai").css("display","block");
                    $("#placeholder .tishiInfo,.contact,.shenhe").css("display","none");
                    $("#placeholder").modal("show");
                }
            }
            schoolData=JSON.stringify(shoolData);
            localStorage.setItem("schoolData",schoolData); 
        });
      
        //审批学校，状态为待审，才能审批
        $("#shenhe").click(function(){
            $("#shenhelist").html("");
            var barr=[];
            //判断状态
            for (var i = 0; i < shoolData.length; i++) {
                if (shoolData[i].status=="B") {
                    //显示学校
                    $("#shenhelist").append(`<option>${shoolData[i].shoolNam}</option>`);
                    barr.push(shoolData[i]);
                }
            }     
            if (barr.length > 0) {
                $("#ShenheSchool").modal("show");
                var selectName =$("#shenhelist option:selected").text();
                for (var j = 0; j < shoolData.length; j++) {
                    if (shoolData[j].shoolNam == selectName) {
                        //显示信息
                        $(".schoolInfo #shenname").html(shoolData[j].shoolNam)
                        $(".schoolInfo #shenCity").html(shoolData[j].shoolArea);
                        $(".schoolInfo #shenAddress").html(shoolData[j].shoolAddress);
                        $(".schoolInfo #shenTel").html(shoolData[j].shoolTel);
                        $(".schoolInfo #shenMaster").html(shoolData[j].headmaster);
                        $(".schoolInfo #shenNum").html(shoolData[j].studentNub);
                        $(".schoolInfo #shenTNum").html(shoolData[j].teacherNub);
                        $(".schoolInfo #shenIP").html(shoolData[j].IP);
                        $(".schoolInfo #shenShuoming").html(shoolData[j].iiustrate);
                        $(".schoolInfo #shenfuzeDept").html(getDepname(shoolData[j].staId));//通过员工id找部门
                        $(".schoolInfo #shenfuzePople").html(getPeople(shoolData[j].staId));
                        $(".schoolInfo #shencurrentStatu").html(statusPuanduan(shoolData[j].shoolId));
                        $(".schoolInfo #shenluruTime").html(shoolData[j].addTime);
                        $(".schoolInfo #shenTime").html(shoolData[j].applyTime);
                    }
               }
           }else{
                $("#ShenheSchool").modal("hide");
                $("#placeholder .tishiInfo,.dongtai,.contact").css("display", "none");
                $("#placeholder .shenhe").css("display", "block");
                $("#placeholder").modal("show");
           }
        });
        //审批不通过
        $("#reject").click(function(){
                var selectName = $("#shenhelist").find("option:selected").text();
                var yijian=$(".schoolInfo #shenyijian").val();
                for(var j = 0; j < shoolData.length; j++){
                    if (shoolData[j].shoolNam == selectName) {
                        shoolData[j].status="C";
                        shoolData[j].opinion=yijian;
                        showData();
                    }
                }
                schoolData=JSON.stringify(shoolData);
                localStorage.setItem("schoolData",schoolData);
                $(".schoolInfo #shenyijian").val("");
        });
        //审批通过
        $("#pizhun").click(function(){
                var selectName = $("#shenhelist").find("option:selected").text();
                var yijian=$(".schoolInfo #shenyijian").val();
                var aggreetTime=new Date().toLocaleDateString();
                for(var i = 0; i < shoolData.length; i++){
                    if (shoolData[i].shoolNam == selectName) {
                        shoolData[i].status="D";
                        shoolData[i].allowedTime=aggreetTime;
                        shoolData[i].opinion=yijian;
                        showData();
                    }
                }
                schoolData=JSON.stringify(shoolData);
                localStorage.setItem("schoolData",schoolData);
                $(".schoolInfo #shenyijian").val("");
        })
        //添加沟通记录
       $("#communicate").click(function(){
            var check=$("#tbList input");
            var ischange=false;
            for(var j=0;j<check.length;j++){
                    if(check[j].checked){
                        ischange=true;
                        break;
                    }
            }
            if(ischange==true){
                $("#addrecode").modal("show");
                commiate();
            }else{
                $("#placeholder .tishiInfo,.dongtai,.shenhe").css("display", "none");
                $("#placeholder .contact").css("display", "block");
                $("#placeholder").modal("show")
                    
            }
       })
       
        $("#addContact").click(function(){
            var id=$("#tbList input:checked").parent().parent().find(".id").text();
            //获取输入的值
            var time = $("#addrecode #contactTime").val();
            var people = $("#addrecode #contacted").val();
            var job = $("#addrecode #job").val();
            var contacter = $("#addrecode #contacter").val();
            var content = $("#addrecode #shuoming").val();
            //添加到数组
            var objContact = { "contactTime": time, "schoolPeople": people, "schoolJob": job, "content": content, "staId": getEmpoId(contacter) }
            for (var i = 0; i < shoolData.length; i++) {
                if (shoolData[i].shoolId == id) {
                    shoolData[i].recordInfo.push(objContact);
                }
            }
            schoolData=JSON.stringify(shoolData);
            localStorage.setItem("schoolData",schoolData);
            $("#addrecode input").val("");
            $("#addrecode textarea").val("");
            $("#tbList input:checked")[0].checked=false;
        });
        $("#addrecode #quxiao").click(function(){
            $("#addrecode input").val("");
            $("#addrecode textarea").val("");
            $("#tbList input:checked")[0].checked=false;
        })
        //全选
        $("#allCheck").click(function () {
            if ($("#allCheck").is(':checked')) {
                $("#tbList input").each(function (index, item) {
                    item.checked = true;
                })
            } else {
                $("tbody input").each(function (index, item) {
                    item.checked = false;
                })
            }

        });

        function check() {
            var isAll = true;
            $("#tbList input").each(function (index, item) {
                // console.log(item.checked)
                if (item.checked == true) {
                    isAll = false;
                }
            })
            if (isAll) {
                $("#allCheck")[0].checked = true;
            } else {
                $("#allCheck")[0].checked = false;
            }
        }

        //分页,点击切换
        function addpages() {
            $("#pages").on("click", ".btn", function () {
                currentPage = Number($(this).text());
                $("#allCheck")[0].checked=false;
                showData();
            })
        }
        //生成页码
        function getPages() {
            //数据总条数
            var total = shoolData.length;
            //总数量/每页显示
            totalPages = Math.ceil(total / page);
            if (totalPages < currentPage) {
                currentPage = totalPages;
            }
            $("#pages").html("")
            for (var i = 1; i <= totalPages; i++) {
                $("#pages").append(`<button class="btn">${i}</button>`)
            }
        };
        //显示所有学校数据
        function showData() {
            //每次变化后先清除
            $("#tbList").html("");
            //开始位置显示数据
            var start = (currentPage - 1) * page;
            //结束
            var end = start + page;
            var statu = "";
            //遍历数组
            for (var i = start; i < end && i < shoolData.length; i++) {
                //添加数据到tbody
                //状态（A:洽谈 B：待审 C：审核不通过 D：推广展开）
                if (shoolData[i].status == "A") {
                    statu = "接洽中";
                } else if (shoolData[i].status == "B") {
                    statu = "待审";
                } else if (shoolData[i].status == "C") {
                    statu = "审核不通过";
                } else if (shoolData[i].status == "D") {
                    statu = "推广展开";
                }
                $("#tbList").append(`<tr>
                                <td><input type="checkbox"></td>
                                <td class="id">${shoolData[i].shoolId}</td>
                                <td>${shoolData[i].shoolNam}</td>
                                <td>${shoolData[i].headmaster}</td>
                                <td>${shoolData[i].addTime}</td>
                                <td>${statu}</td>
                                <td><span class="displayData">查看</span><span class="updateData">修改</span></td>
                            </tr>`)
            }
        };
        //选择城市，切换相应的学校
        $("#selectCity").change(function () {
            $("#tbList").html("");
            //获取选中的值
            var city = $(this).find("option:selected").text();
           
            //判断学校的城市
            for (var i = 0; i < shoolData.length; i++) {
                if (city == shoolData[i].shoolArea) {
                    $("#tbList").append(`<tr>
                                <td><input type="checkbox"></td>
                                <td class="id">${shoolData[i].shoolId}</td>
                                <td>${shoolData[i].shoolNam}</td>
                                <td>${shoolData[i].headmaster}</td>
                                <td>${shoolData[i].addTime}</td>
                                <td>${statusPuanduan(shoolData[i].shoolId)}</td>
                                <td><span class="displayData">查看</span><span class="updateData">修改</span></td>
                            </tr>`)

                        $("#pages").css("display", "none");
                }else if (city == "所有") {
                    $("#pages").css("display", "block");
                    showData();
                }
            }
          
        });
        //搜索
        $(".searchBtn").click(function(){
            var sval = $("#searchval").val();
            var regexp = new RegExp(sval, 'g')
            //匹配的数组
            var pattern = [];
            $("#tbList").html("");
            for (var i = 0; i < shoolData.length; i++) {
                pattern.push(shoolData[i].shoolNam);
                if (regexp.test(shoolData[i].shoolNam)) {
                    // console.log(shoolData[i]);
                    $("#tbList").append(`<tr>
                                <td><input type="checkbox"></td>
                                <td class="id">${shoolData[i].shoolId}</td>
                                <td>${shoolData[i].shoolNam}</td>
                                <td>${shoolData[i].headmaster}</td>
                                <td>${shoolData[i].addTime}</td>
                                <td>${statusPuanduan(shoolData[i].shoolId)}</td>
                                <td><span class="displayData">查看</span><span class="updateData">修改</span></td>
                                    </tr>`);
                }
            }
            $("#searchval").val("");
        })
        //判断状态
        function statusPuanduan(id) {
            var statu = "";
            for (var i = 0; i < shoolData.length; i++) {
                if (shoolData[i].shoolId == id) {
                    //状态（A:洽谈 B：待审 C：审核不通过 D：推广展开）
                    if (shoolData[i].status == "A") {
                        statu = "接洽中";
                    } else if (shoolData[i].status == "B") {
                        statu = "待审";
                    } else if (shoolData[i].status == "C") {
                        statu = "审核不通过";
                    } else if (shoolData[i].status == "D") {
                        statu = "推广展开";
                    }
                }

            }
            return statu;
        }
        //获取对应的部门
        function getDepname(id) {
            var depid;
            var depname;
            for (var i = 0; i < staffDate.length; i++) {
                if (id == staffDate[i].staId) {
                    depid = staffDate[i].depId;
                    for (var j = 0; j < departmentDate.length; j++) {
                        if (depid == departmentDate[j].depId) {
                            depname = departmentDate[j].depNam;
                        }
                    }
                }

            }
            return depname;
        }
        //获取对应的负责人
        function getPeople(id) {
            var managerName;
            for (var i = 0; i < staffDate.length; i++) {
                if (id == staffDate[i].staId) {
                    managerName = staffDate[i].name;
                }
            }
            return managerName;
        }
        //删除数组中的值
        function delData(id) {
            for (var i = 0; i < shoolData.length; i++) {
                if (shoolData[i].shoolId == id) {
                    shoolData.splice(i, 1);
                    break;
                }

            }
        }
        //根据员工名字找id
        function getEmpoId(name) {
            var id;
            for (var i = 0; i < staffDate.length; i++) {
                if (name == staffDate[i].name) {
                    id = staffDate[i].staId;
                }
            }
            return id;
        }

        //动态生成部门列表
        function getDeptList(){
            for(var i=0;i<departmentDate.length;i++){
                $("#addNewSchool #dept").append(`<option>${departmentDate[i].depNam}</option>`);
            }
        }
         //对应部门的员工
        $("#addNewSchool #dept").change(function(){
            $("#fuzePople").html("")
            //获取选中的值
            var yuangong = $(this).find("option:selected").text();
            for(var j=0;j<departmentDate.length;j++){
                if(departmentDate[j].depNam==yuangong){
                    for(var i=0;i<staffDate.length;i++){
                        if(staffDate[i].depId==departmentDate[j].depId){
                            $("#addNewSchool #fuzePople").append(`<option>${staffDate[i].name}</option>`);
                        }
                    }
                }
            }
            
        })
        //市场部人员
        function commiate(){
            $("#addrecode #contacter").html("");
                    for(var j=0;j<staffDate.length;j++){
                        if(staffDate[j].depId=="003"){
                            $("#addrecode #contacter").append(`<option>${staffDate[j].name}</option>`);
                        }
                    }
                
        }
        $("#addNewSchool form ").find('input:required').each(function () {
            var reinput = $("<strong class='red'>*</strong>");
            //添加到this对象的父级对象下
            $(this).parent().append(reinput);
        });
        $("#addNewSchool form ").find('select:required').each(function () {
            var reinput = $("<strong class='red'>*</strong>");
            //添加到this对象的父级对象下
            $(this).parent().append(reinput);
        });
        $("#addNewSchool form ").find('input:required').blur(function(){
            // console.log($(this))
            $(this).parent().find("span").remove();
            if($(this).val()==""){
                $(this).parent().append("<span class='red'>此为必填项</span>");
            }
        });
         //判断输入合法性 
         $("#addNewSchool #sId").blur(function(){
           
            for(var i=0;i<shoolData.length;i++){
                $(this).parent().find(".ts").remove();
                if(shoolData[i].shoolId==$("#addNewSchool #sId").val()){
                    $(this).parent().append("<span class='red ts'>该id已存在</span>");
                    break;
                }
                else{
                    $(this).parent().append("<span class='green ts'>正确</span>");
                }
            }
        });
        $("#addNewSchool #sTelNum").blur(function(){
            var reg= /^((0\d{2,3}-\d{7,8})|(1[3584]\d{9}))$/;
            $(this).parent().find(".tel").remove();
            if(!reg.test($("#addNewSchool #sTelNum").val())){
                $(this).parent().append("<span class='red tel'>输入不规范</span>");
            }else{
                $(this).parent().append("<span class='green tel' >通过</span>");
            }
        })